package com.tuantuan.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tuantuan.dao.ClassrequireDao;
import com.tuantuan.dao.StudentDao;
import com.tuantuan.model.Classrequire;
import com.tuantuan.model.Students;
import com.tuantuan.service.StudentService;
/**
 * 学生基础数据控制层
 * @author Administrator
 *
 */
@Controller
public class StudentController {
	@Resource(name="StudentDao")
	private StudentDao stuDao;
	
	@Resource(name="StudentService")
	private StudentService stuSer;
	
	@Autowired
	private ClassrequireDao claRequire;

	/**
	 * 学生列表查询（全部）
	 * @param request
	 * @param response
	 * @param s
	 * @return
	 */
	@RequestMapping("/student/queryStudents.do")
	@ResponseBody
	public Map<String,Object>  queryByPage(HttpServletRequest request,HttpServletResponse response,Students s){
		Map<String,Object> map=new HashMap<String, Object>();
		Students stu = stuDao.queryStuByPage(s);
		map.put("page", stu);
		return map;
		
	}
	/**
	 * 学生信息添加页面初始化
	 * @param request
	 * @param c
	 * @return
	 */
	@RequestMapping("/student/tosAddtudent.do")
	private String toAddStudent(HttpServletRequest request, Classrequire c){
		List<Classrequire> list = claRequire.queryAllClassrequire(c);
		//班级资料
		request.setAttribute("classAll", list);
		return "student/addStudent";
	}
	/**
	 * 学生查询全部
	 * @param request
	 * @param c
	 * @return
	 */
	@RequestMapping("/student/toQueryStudents.do")
	private String toQueryStudents(HttpServletRequest request, Classrequire c){
		List<Classrequire> list = claRequire.queryAllClassrequire(c);
		request.setAttribute("classAll", list);
		return "student/students";
	}
	/**
	 * 学生信息添加
	 * @param request
	 * @param response
	 * @param s
	 * @return
	 */
	@RequestMapping("/student/addStudents.do")
	@ResponseBody
	public String  addStudent(HttpServletRequest request,HttpServletResponse response,Students s){
		return stuSer.addStudent(s);
	}

	/**
	 * 学生信息更新界面加载
	 * @param request
	 * @param stuId 学生主键ID
	 * @return
	 */
	@RequestMapping("/student/toUpdateStudents.do")
	private String toUpdateStudents(HttpServletRequest request, int stuId){
		List<Classrequire> list = claRequire.queryAllClassrequire(new Classrequire());
		Students s = new Students();
		s.setStuId(stuId);
		Students stu = stuDao.queryStuById(s);
		request.setAttribute("classAll", list);
		request.setAttribute("students", stu);
		return "student/studentView";
	}
	
	/**
	 * 学生资料更新处理
	 * @param request
	 * @param response
	 * @param s
	 * @return
	 */
	@RequestMapping("/student/updateStudents.do")
	@ResponseBody
	public String  updateStudent(HttpServletRequest request,HttpServletResponse response,Students s){
		return stuSer.updateStudent(s);
	}
	
	/**
	 * 学生信息删除操作
	 * @param request
	 * @param stuId
	 * @param pageCounts
	 * @return
	 */
	@RequestMapping("/student/deleteStudents.do")
	public String deleteStudent(HttpServletRequest request,int stuId,int pageCounts){
		String flag = stuSer.deleteStuden(stuId);
		List<Classrequire> list = claRequire.queryAllClassrequire(new Classrequire());
		request.setAttribute("classAll", list);
		request.setAttribute("flag", flag);
		request.setAttribute("pageCounts", pageCounts);
		return "student/students";
		
	}
	
	
	//手机与web交互
	@RequestMapping("/student/StudentLogin.do")
	@ResponseBody
	public String StudentLogin(HttpServletRequest request,HttpServletResponse response,Students s){
		String result=stuSer.StudentLogin(s);
		
		return result;
	}
	
	/**
	 * 
	 * 查询同班的同学
	 * 方法名：queryStudentByClassId<BR>
	 * 时间：2016年2月28日-下午3:29:59 <BR>
	 * @param request
	 * @param response
	 * @param classId
	 * @return String<BR>
	 * TODO
	 */
	@RequestMapping("/student/queryStudentByClassId.do")
	@ResponseBody
	public String queryStudentByClassId(HttpServletRequest request,HttpServletResponse response,String classId){
		
		return stuSer.queryStudentByClassId(classId);
	}
	/**
	 * 
	 * 模糊查询
	 * 方法名：queryStudentByName<BR>
	 * 时间：2016年2月28日-下午3:50:49 <BR>
	 * @param request
	 * @param response
	 * @param name
	 * @return String<BR>
	 * TODO
	 */
	@RequestMapping("/student/queryStudentByName.do")
	@ResponseBody
	public String queryStudentByName(HttpServletRequest request,HttpServletResponse response,String name){
		return stuSer.queryStudentByName(name);
	}
	
	
	
	
	
	
	
	
	
	
	
	public StudentDao getStuDao() {
		return stuDao;
	}

	public void setStuDao(StudentDao stuDao) {
		this.stuDao = stuDao;
	}

	public StudentService getStuSer() {
		return stuSer;
	}

	public void setStuSer(StudentService stuSer) {
		this.stuSer = stuSer;
	}
	
	
	
}
